<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { useAppStore } from '@/stores'
const { safeAreaInsets } = useAppStore().getSystemInfo()
const emit = defineEmits(['leftClick', 'rightClick'])
// 定义 props 接收
defineProps<{
  title: string
  leftText?: string
  bgColor?: string
  bgImage?: string
  fontColor?: string
}>()

const leftClick = async function () {
  emit('leftClick')
}

onLoad(() => {
  console.log(safeAreaInsets)
})

// props 接收父组件 title参数
</script>
<template>
  <view
    class="navbar"
    :style="{ 
    paddingTop: safeAreaInsets!.top + 10 + 'px',
    backgroundColor: bgColor? bgColor : '#f5f5f5',
    backgroundImage: bgImage? 'url(' + bgImage + ')' : 'none',
    color: fontColor? fontColor : '#000'
    }"
  >
    <view class="left">
      <text @tap="leftClick">{{ leftText }}</text>
      <!-- 插槽 -->
      <slot name="left"></slot>
    </view>
    <text class="center">{{ title }}</text>
    <view class="right"> </view>
  </view>
</template>

<style scoped lang="scss">
.navbar {
  width: 750rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #f5f5f5;
  font-size: 32rpx;
  padding-top: 58px;
  height: 30px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .left {
    color: 26rpx;
    cursor: pointer;
    flex: 1;
  }
  .center {
    font-weight: bold;
    flex: 1;
    text-align: center;
  }
  .right {
    color: 26rpx;
    cursor: pointer;
    flex: 1;
    text-align: right;
    position: relative;
  }
}
</style>
